# Make findutils.

# Copyright (C) 1996-2021 Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

AUTOMAKE_OPTIONS = gnu std-options readme-alpha

AM_CFLAGS = $(WARN_CFLAGS)

EXTRA_DIST = \
	COPYING \
	ChangeLog \
	README-hacking \
	THANKS \
	TODO \
	build-aux/git-version-gen \
	config.h.in \
	stamp-h.in \
	tests/GNUmakefile \
	tool-versions.txt

DISTCLEANFILES = tool-versions.txt


# "gnulib-tests" is the gnulib unit test dir.
SUBDIRS = gl build-aux lib find xargs locate doc po m4 gnulib-tests

ALL_RECURSIVE_TARGETS =

ACLOCAL_AMFLAGS = -I gl/m4 -I m4

TESTFILE_SUFFIXES = .exp .xo .xe .xi

tool-versions.txt: Makefile
	( automake --version ; echo ; \
	autoconf --version ; echo ; \
	$(CC) --version ; echo ; \
	m4 --version ; echo ; \
	gettext --version ; echo ; \
	runtest --version ; echo ; \
	makeinfo --version ) > $@

# Have .tarball-version based versions only in tarball builds.
dist-hook: gen-ChangeLog findutils-check-testfiles
	$(AM_V_GEN)echo $(VERSION) > $(distdir)/.tarball-version

# gen-Changelog must still work when $(top_srcdir)/.git does not exist
# because "make distcheck" verifies that you can "make dist" from the
# tarball generated by "make dist".  We still need that to work.
.PHONY: gen-ChangeLog
gen-ChangeLog:
	$(AM_V_GEN)if test -d $(top_srcdir)/.git; then             \
	  $(AUXDIR)/gen-changelog.sh $(top_srcdir) > $(distdir)/cl-t \
	      && { rm -f $(distdir)/ChangeLog                      \
		     && mv $(distdir)/cl-t $(distdir)/ChangeLog; } \
	else                                                       \
	  echo "WARNING: $@: cannot generate ChangeLog since" >&2 && \
	  echo "$(top_srcdir) has no .git subdirectory" >&2 ;      \
	fi

## Check that we actually shipped all the test files that exist in the source.
## runtest will run all the .exp files it finds, and so if we don't ship all
## of them, there will be some tests which people using the CVS code will be
## running, but people using the source distribution will not.
findutils-check-testfiles:
	@echo
	$(AUXDIR)/check-testfiles.sh "$(distdir)" "$(srcdir)" $(TESTFILE_SUFFIXES)


findutils-check-smells:
	find  $(srcdir) \( -path $(srcdir)/autom4te.cache -o  \
                           -path $(srcdir)/gnulib     -o  \
                           -path $(srcdir)/gl     -o  \
                           -path $(srcdir)/gnulib-tests -o  \
                           -name .git             -o  \
                           \( -type d -name CVS \)  \
                       \) -prune -o                  \
	\( -type f -o -type l \)  \
	\! \( -name '*~' -o -name '*.xo' -o -name '*.xi' \) \
	-print0 | \
	xargs -0 python $(AUXDIR)/src-sniff.py

# Update gnulib to latest, merging some additional files we take from there
# as well.  This only works if the working tree of both findutils and gnulib
# are clean (which is checked first).
# The following is a good start to find additional candidates for copying:
#  git ls-files \
#    | sed 's,^.*/,,g; /^gnulib$/d; /^t-t$/d; /\.c$/d' \
#    | grep -Ff - <( cd  gnulib && git ls-files )
.PHONY: gnulib-sync update-gnulib-to-latest
gnulib-sync update-gnulib-to-latest:
	@( cd $(srcdir) \
	    && { printf 'gnulib: ' && git -C gnulib describe --always --dirty \
		  && printf 'findutils: ' &&  git describe --always --dirty \
		  || echo dirty; \
		  } | grep 'dirty$$' \
			&& { echo "error: tree is dirty" >&2; exit 1; } || : \
	    && git submodule foreach git pull origin master \
	    && cp -v gnulib/doc/COPYINGv3 COPYING \
	    && cp -v gnulib/doc/fdl-1.3.texi doc/fdl.texi \
	    && cp -v gnulib/build-aux/bootstrap bootstrap \
	    && cp -v gnulib/tests/init.sh tests/init.sh \
	    && git status --short -- gnulib COPYING doc/fdl.texi bootstrap \
		 tests/init.sh \
	)

# Clean coverage files generated by running binaries built with gcc
# -fprofile-arcs -ftest-coverage.  We touch subdirectories here
# because the relevant Makefile.am files (which we would otherwise
# edit to add an $(RM) command in their own coverage-clean rule) are
# generated by gnulib-tool and therefore we cannot add the rule to
# those files.
coverage-clean:
	for dir in . gl/lib gl/lib/glthread gl/lib/uniwidth gnulib-tests     \
	  gnulib-tests/uniwidth; do                                          \
	  rm -f $${dir}/*.gcno $${dir}/*.gcda $${dir}/*.gcov $${dir}/*.lcov; \
	done

clean-local: coverage-clean

include $(top_srcdir)/tests/local.mk
